import { Component, Input, EventEmitter, Output } from "@angular/core";
import { ColumnOptions, ColumnType } from "../models/columnOptions.model";
import { ButtonType } from "../models/tableButton.model";

@Component({
    selector: 'cell',
    templateUrl: 'tableCell.component.html',
    styleUrls: ['tableCell.component.scss', '../table.component.scss']
})
export class TableCellComponent {

    public columnType: typeof ColumnType = ColumnType;

    public buttonType: typeof ButtonType = ButtonType;

    @Input() options: ColumnOptions;

    @Input() value: any;

    @Output() buttonClicked: EventEmitter<any> = new EventEmitter<any>();

    public isDate(val: any): boolean { return val instanceof Date; }

    public onButtonClicked(actionOptions: any) {
        this.buttonClicked.emit(actionOptions);
    }

    public getClass(value: any): string {
        let ret: string = '';
        let button = this.options.columnButtons.find(x => x.value == value);
        if (button) ret = button.classNameOn
        return ret;
    }
}